$(function(){
	var listDiv = $(".list-content dd");
	var listSize = listDiv.size();

	//订单tab切换
	$(".list-title").on("click", "dt", function(){
		$(".list-title dt").removeClass("cur");
		$(this).addClass("cur");
		go();
	});
	$("#orderSelect").on("change",function(){
		go();
	})
	

	//订单列表--hover显示收货信息
	$(".order-info").hover(function(){
		var thisHtml = $(this),
			dataId = parseInt($(this).parents("dd").attr("data-id"));
		$.ajax({
			url: mesUrl,
			type: "get",
			data:{orderInfoId:dataId},
			success: function(data){
				if(data){
					var addr = data.province + data.city + data.county + data.address;
					thisHtml.find("span").remove();
					thisHtml.append('<span>'+ data.consignee + '<br>' + addr + '<br>' +data.mobile_phone + '</span>')
				}
			},
			error: function(){
				thisHtml.find("span").remove();
				thisHtml.append('<span>暂无信息</span>')
			}
		});	
	})

	
	

	//支付倒计时
	$(".countdown").each(function(){
		dateCountDown(this,parseInt($(this).attr("data-time")));
	});
	

	//取消订单操作
	$(document).on("click",".cancel-btn",function(e){
		e.preventDefault();
		var cancelUrl = $(this).attr("href");
		$.confirm(["温馨提示","是否取消订单","是","否"],function(){
			$.doAjax({
				url: cancelUrl,
				success: function(data){
					console.log(data)
					if(data.flag){
						location.reload();
						
					}else{
						$.alert(data.msg);
					}
				}
			})
		});
	})

	//确认收货操作
	$(document).on("click",".btn-getgoods",function(e){
		e.preventDefault();
		var confirmUrl = $(this).attr("href");
		$.confirm(["温馨提示","是否确认收货","是","否"],function(){
			$.doAjax({
				url: confirmUrl,
				success: function(data){
					console.log(data)
					if(data.flag){
						location.reload();
					}else{
						$.alert(data.msg);
					}
				}
			})
		});
	})


})
function go(){
	timesolt = $("#orderSelect").val();
	status = $(".list-title dt.cur").attr("data-id");
	window.location.href=curUrl+timesolt+"&status="+$(".list-title dt.cur").attr("data-id");
}


function dateCountDown(obj,t) {
    if(t > 0) {
        t --;
        $(obj).children("em").text(timeFormat(t));
    }
	setTimeout(function(){
		dateCountDown(obj,t);
	},1000);
}

function timeFormat(t){
	var day = parseInt(t/(24*3600));
	var hour = parseInt((t-(day*24*3600))/3600);
	hour = hour<10?"0"+hour:hour;
	var min = parseInt((t-(day*24*3600)-hour*3600)/60);
	min = min<10?"0"+min:min;
	var sec = parseInt(t-(day*24*3600)-hour*3600-min*60);
	sec = sec<10?"0"+sec:sec;
	if(day==0){
		return hour+":"+min+":"+sec;
	}else{
		return day+":"+hour+":"+min+":"+sec;
	}
}
